<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
<head>
	<jsp:include page="../inc_bootstrap.jsp"></jsp:include>
	<title>公告</title>
	<link rel="stylesheet" href="${ctx}/css/iconfont.css"/>
	<style>
		/*添加按钮*/
		.query{
			line-height:25px;
		}
		
	</style>
	<script type="text/javascript">

		$(function() {
			//先销毁表格
			$('#bootTable').bootstrapTable({
				url: "${ctx}/notice/noticePage",
				dataType: "json",
				method: 'get',
				cache: false,
				height: "auto",//
				striped: true,
				pagination: true,
				pageSize: 20,
				pageNumber:1,
				pageList: [10, 20, 50, 100, 200, 500],
				search: true,
				showColumns: true,
				showRefresh: true,
				clickToSelect: true,
				idField:'id',
				toolbar: "#toolbar",
				paginationHAlign: 'left',
				paginationDetailHAlign: 'right',
				sidePagination: "server", //表示服务端请求
				queryParamsType : "undefined",
				columns: [
					{field:"id",title:"",align:"left",valign:"middle",sortable:"true",visible:false},
					{field:"title",title:"标题",align:"left",valign:"middle",sortable:"true",
						formatter: function(value, row, index) {
							var str = '<a href="${ctx}/notice/view/'+row.id+'">'+row.title+'</a>';
							return str;
						}
					},
					{field:"createTime",title:"创建时间",align:"left",valign:"middle",sortable:"true"},
					{field:"createName",title:"创建人",align:"left",valign:"middle"},
					{field:"status",title:"操作",align:"center",valign:"middle",
						formatter: function(value, row, index) {
							var str = '';
									str += $.formatString('<div style="width:180px;height:20px;margin:0 auto;"><span class="mynewBtn" style="background: #34c0e3;border:1px solid #34c0e3;" onclick="editFun(\'{0}\');" >编辑</span>', row.id);
									//'<i class="icon iconfont" title="编辑" onclick="editFun(\'{0}\')>&#xe601;</i>'
									str += '&nbsp;&nbsp;';
									str += $.formatString('<span class="mynewBtn" style="background: #34c0e3;border:1px solid #34c0e3;" onclick="delFun(\'{0}\');" >删除</span>                ', row.id);
							return str;
						}
					}
				],
				onPageChange: function (size, number) {
					//$("#pageSizeInput").val(size);
					//$("#pageNumberInput").val(number);
					//var form = $('#tableForm');
					//form.action= '${base}/showReport';
					//form.submit();
				},
				onSort: function (name, order) {
				},
// 			formatShowingRows: function (pageFrom, pageTo, totalRows) {
// 				return '';
//             },
// 			formatRecordsPerPage: function () {
// 				return '';
//             },
				formatNoMatches: function(){
					return '无符合条件的记录';
				}
			}); 
		});

		function getSelect(){
			var rows = getIdSelections();
			alert(rows);
			window.location.href='${ctx}/log/view?id='+rows;
		}
		function getIdSelections() {
			return $.map($('#bootTable').bootstrapTable('getSelections'), function(row) {
				return row.id
			});
		}
		function noticeAdd(){
			window.location.href='${ctx}/np/noticeAdd';
		}
		function editFun(id){
			window.location.href='${ctx}/notice/noticeEdit/'+id+"?temp="+Math.random();
		}
		function delFun(id){
			$.post('${ctx}/notice/del/'+id, {
			}, function(result) {
				if (result.success) {
					layer.alert('公告删除成功！',{skin:'layui-layer-lan',title: ['系统提示', 'background-color:#00B2EE; color:#fff;'],closeBtn: 0}, function(index){
						$('#bootTable').bootstrapTable('refresh', {url: '${ctx}/notice/noticePage'});  
					    layer.close(index);
					});
				}else{
					layer.alert('公告删除失败！',{skin:'layui-layer-lan',title: ['系统提示', 'background-color:#00B2EE; color:#fff;'],closeBtn: 0}, function(index){
					    layer.close(index);
					})
				}
			}, 'JSON');
		}
	</script>
</head>
<body >
<jsp:include page="../head.jsp"></jsp:include>
<div id="content" class="divBox">
	<table id="bootTable" class="table-striped"></table>
</div>
<div id="toolbar">
	<input type="button" class="query" value="&nbsp;&nbsp;添加&nbsp;&nbsp;" onclick='noticeAdd()'/>
</div>
<jsp:include page="../footer.jsp"/>
</body>
</html>